local fk__beili = fk.CreateSkill {

  name = "fk__beili",

  tags = {  },

}

local U = require "packages/utility/utility"


fk__beili:addEffect(fk.Damaged, {
  name = "fk__beili",
  events = {fk.Damaged},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fk__beili.name) and not target.dead and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForDiscard(player, 1, 1, true, fk__beili.name, true, ".", "#fk__beili-discard::"..target.id, true)
    if #card > 0 then
      event:setCostData(self, {
        cards = card,
        tos = {target.id},
      })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.simpleClone(event:getCostData(self).cards)
    local draw = Fk:getCardById(cards[1]):getMark("@@fk__guici-inhand") > 0
    room:throwCard(cards, fk__beili.name, player, player)
    if not target.dead then
      target:drawCards(1, fk__beili.name)
    end
    if draw and not player.dead then
      player:drawCards(1, fk__beili.name)
    end
  end,
})

return fk__beili